#ifndef __timer_h__
#define __timer_h__ 1
#include "sys.h"


#define TIMER_LOCK_T pthread_mutex_t
#define TIMER_LOCK_INIT(x) pthread_mutex_init(x, NULL)
#define TIMER_LOCK(x) pthread_mutex_lock(x)
#define TIMER_UNLOCK(x) pthread_mutex_unlock(x)

typedef void (*tmr_cb)(void* arg);

struct timer_s {
    struct timeval expire;
    struct timeval tm, clock_tm;
    tmr_cb cb;
    TAILQ_ENTRY(timer_s) entry;
};

TAILQ_HEAD(Timer_head, timer_s);

void timer_add(struct Timer_head* head, struct timer_s* new);
struct timer_s* timer_pop(struct Timer_head* head);
struct timer_s* timer_new(struct timeval* tm, tmr_cb cb);
void timer_free(struct timer_s* tmr);
void timer_show(struct Timer_head* head);
void timer_call(struct timer_s* tmr);
#endif